package com.zsl.swing.redis.desktop.type;

import java.util.Arrays;
import java.util.Optional;

public enum RedisTypeEnum {
    NONE("none", -1L),STRING("string",20480L),LIST("list", 500L),SET("set", 500L),ZSET("zset",500L),HASH("hash",10240);

    private final String type;

    private final long limit;

    RedisTypeEnum(String type,long limit){
        this.type = type;
        this.limit = limit;
    }

    public long getLimit(){
        return this.limit;
    }

    public static long getLimitByType(String type){
        Optional<RedisTypeEnum> any = Arrays.stream(values()).filter(one -> one.type.equalsIgnoreCase(type)).findAny();
        return any.map(redisTypeEnum -> redisTypeEnum.limit).orElse(-1L);
    }

    public static RedisTypeEnum getRedisType(String type){
        Optional<RedisTypeEnum> any = Arrays.stream(values()).filter(one -> one != NONE).filter(one -> one.type.equalsIgnoreCase(type)).findAny();
        return any.orElse(null);
    }

    public static boolean isString(String type) {
        return STRING.type.equals(type);
    }

    public static boolean isList(String type){
        return LIST.type.equals(type);
    }

    public static boolean isSet(String type){
        return SET.type.equals(type);
    }

    public static boolean isZSet(String type){
        return ZSET.type.equals(type);
    }

    public static boolean isHash(String type){
        return HASH.type.equals(type);
    }

    public String getType(){
        return this.type;
    }

    public static boolean isRedisType(String type){
        Optional<RedisTypeEnum> any = Arrays.stream(values()).filter(e -> e.getType().equals(type)).findAny();

        return any.isPresent() && any.get() != NONE;
    }
}
